﻿@model Ducu.SRV.ViewModel.Shared._PagerModel

<nav>
    <ul class="pagination">
        @{
            int begin = 0;
            if (Model.PageIndex > 1)
            {
                begin = ((Model.PageIndex - 1) / Model.RowSize) * Model.RowSize;
            }
            int end = begin + Model.RowSize;
            int sumOfPage = Model.SumOfPage;
            end = end > sumOfPage ? sumOfPage : end;
        }
        @if (Model.PageIndex > 1)
        {
            <li><a id="@(Model.PageIndex - 1)" href="@string.Format(Model.FormatUrl, Model.PageIndex - 1)">&lt;&lt;</a></li>
        }
        @for (int i = begin; i < end; i++)
        {
            string currentPage = (i + 1 == Model.PageIndex) ? "active" : string.Empty;
            <li class="@currentPage"><a id="@(i + 1)" href="@string.Format(Model.FormatUrl, i + 1)">@(i + 1)</a></li>
        }
        @if (Model.PageIndex < sumOfPage)
        {
            <li><a id="@(Model.PageIndex + 1)" href="@string.Format(Model.FormatUrl, Model.PageIndex + 1)">&gt;&gt;</a></li>
        }
    </ul>
</nav>